package main

import (
	"fmt"
)

//定义结构体
type user struct {
	age  int
	name string
	sex  string
}

func main() {
	var student = user{18, "Athena", "male"}
	teacher := user{28, "mark", "female"}
	var person user

	//必须给每个字段赋值
	person.name = "test"
	person.age = 30
	person.sex = "female"

	u := &user{18, "siyuan", "female"}
	fmt.Println("new:", *u)
	fmt.Println(student.name)
	fmt.Println(teacher.name)
	fmt.Println(student)
	fmt.Println(person)

	printUser(teacher)

	var ptr *user
	ptr = &teacher
	fmt.Printf("user结构体的内存地址：%d\n", ptr)
	printPointer(ptr)
}

//打印user结构体的每个属性
func printUser(u user) {
	fmt.Println("准备打印u的name属性：")
	fmt.Println(u.name)
}

//通过结构体的指针访问结构体属性值
func printPointer(ptr *user) {
	fmt.Println(ptr.name)
}
